<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <meta http-equiv='X-UA-Compatible' content='ie=edge'>
    <title>骏怡连锁酒店后台管理-登录</title>
    <link rel='shortcut icon' href='../favicon.ico'>
    <!-- Amaze Styles-->
    <link rel='stylesheet' href='../assets/css/amazeui.min.css'/>
    <!-- Sweet Alert-->
    <link rel='stylesheet' href='../assets/css/sweetalert2.min.css'>
    <style>
        html,
        body {
            margin: 0;
            padding: 0;
            height: 100%;
            overflow: hidden;
        }

        body {
            background: url(../assets/img/login.jpg)no-repeat;
            background-size: cover;
            overflow: hidden;
        }

        .whole {
            width: 100%;
            height: 100%;
        }

        .left {
            width: 50%;
            float: left;
        }

        .right {
            width: 50%;
            ;
            float: left;
        }

        .content {
            width: 450px;
            height: 300px;
            background: transparent;
            margin: 200px auto;
            margin-left: 0;
            text-align: center;
            color: white;
            border-left: 2px solid rgb(31, 40, 55);
        }

        input {
            margin-top: 30px;
        }

        button {
            outline: medium;
            margin-top: 30px;
            width: 170px;
            border: 1px solid rgb(244, 67, 54);
            border-radius: 50px;
            background: rgb(31, 40, 55);
            color: white
        }

        .a input {
            border: none;
            outline: medium;
            background: transparent;
            border-bottom: 1px solid rgb(31, 40, 55);
            color: #fff
        }

        button:hover {
            cursor: pointer;
        }

        .center {
            width: 450px;
            height: 100px;
            text-align: center;
            color: white;
            font-size: 30px;
            margin: 300px auto;
            margin-right: 0;

        }
        #btnzmx{
         margin-bottom: 20px;
        float: right;
     }
    </style>
</head>

<body>
    <div class='whole'>
        <div class='left'>
            <div class='center'>
                <img src='../favicon.ico' />
                <br>骏怡连锁酒店后台管理系统</div>
        </div>
        <div class='right'>
            <div class='content'>
                <h2>用户登录</h2>
                <div class='a'>
                    <i class='fa fa-user'></i>
                    <input type='username' id='username' placeholder='请输入用户名或手机号' autocomplete='off'>
                </div>
                <div class='a'>
                    <i class='fa fa-lock'></i>
                    <input type='password' id='password' placeholder='请输入密码' autocomplete='off'>
                </div>
                <div style='margin-top: 10px;'>
                    <label>
                            <input id='remember' type='checkbox'>记住密码
                    </label>
                </div>
                <button id='btn' class='am-btn am-btn-primary'>登录</button>
            </div>
        </div>
    </div>
</body>
<script src='../assets/js/jquery.min.js'></script>
<!-- Sweet Alert -->
<script src='../assets/js/sweetalert2.min.js'></script>
<script>
    //登录
    $('#password').keyup(function(e){
        if(e.keyCode===13){
            $('#btn').click();
        }
    })

    $('#btn').click(function(){
        let username = $('#username').val();
        let password = $('#password').val();
        if(username.trim()=='' || password.trim()==''){
            swal('登录失败','用户名或密码不能为空','error');
            return;
        }

        //Ajax异步请求(无刷新请求)
        $.ajax({
            url:'/login.do',
            method:'POST',
            data:`username=${username}&password=${password}`,
            success:function(result){
                if(result==='success'){
                    //如果勾选了记住密码，则存储在localStorage和sessionStorage
                    if($('#remember').prop('checked')){
                        localStorage.setItem('username',username);
                    }
                    sessionStorage.setItem('username',username);
                    location.href='/';
                }else{
                    alert('失败');
                }
            }
        })
    })
</script>
</html>